package com.m8n6.demo2.service.before;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.m8n6.demo2.common.http.ResponseResult;
import com.m8n6.demo2.entity.FocusEntity;
import com.m8n6.demo2.mapper.before.FocusMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @author xujia
 */
@Service
public class FocusServiceImpl extends ServiceImpl<FocusMapper, FocusEntity> implements FocusService {
    @Override
    public ResponseResult<Map<String, Object>> addFocus(FocusEntity focusEntity) {
        Long count = lambdaQuery()
                .eq(FocusEntity::getGoodstableId, focusEntity.getGoodstableId())
                .eq(FocusEntity::getBusertableId, focusEntity.getBusertableId())
                .count();
        if (count > 0) {
            return ResponseResult.getMessageResult(null, "A001");
        }

        focusEntity.setFocustime(new Date());
        if (save(focusEntity)) {
            return ResponseResult.getMessageResult(null, "A002");
        }

        return ResponseResult.getMessageResult(null, "A003");
    }
}

